<template>
  <!--其他企业新增/编辑弹窗-->
  <a-modal  :maskClosable="false"
            :title="mdl.dialogTitleMap[mdl.dialogStatus]"
            :width="1000"
            @ok="mdl.dialogStatus === 'create' ? createData() : updateData()"
            v-model="mdl.visible"
            :confirm-loading="loading"
  >
    <a-form>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="企业名称"
      >
        <a-input placeholder="" v-model="mdl.formData.companyName"/>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="处罚日期"
      >
        <a-date-picker @change="onChangepulishTime" :value="moment(mdl.formData.pulishTime, dateFormat)"/>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="处理期限"
      >
        <a-date-picker @change="onChangedealTime" :value="moment(mdl.formData.dealTime, dateFormat)"/>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="处罚文书号"
      >
        <a-input placeholder="" v-model="mdl.formData.pulishNo"/>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="所属法律法规"
      >
        <a-select mode="multiple"
                  placeholder="请选择法律法规"
                  @change="handleChange"
                  :value="flfgValueList"
                  allowClear>
          <a-select-option :key="item.id" v-for="(item, index) in flfgList">{{item.name}}</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="地址"
      >
        <a-input placeholder="" v-model="mdl.formData.address"/>
      </a-form-item>
      <a-form-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="法人"
      >
        <a-input placeholder="" v-model="mdl.formData.personName"/>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
  import moment from 'moment';
  import {infoDocIquery} from '@/api/invoice'
  import {companyInfoBaseup,companyInfoBaseinsert} from '@/api/business'
  export default {
    components: {

    },
    props: {
      /*   -------弹窗--------*/
      mdl: [Array,Object,String],
      flfgValueList: [Array,Object,String],
    },
    data() {
      return {
        flfgList: [],
        dateFormat: 'YYYY-MM-DD',
        loading: false
      }
    },
    inject: ['upShow'],
    created() {
      this.getFlfgList()
    },
    watch: {

    },
    computed: {

    },
    methods: {
      moment,
      //查询法律法规名称
      getFlfgList() {
        const parameter = {
          _search: false,//是否分页查询
          pageSize: '',
          pageNumber: '',
          bgTm: "",
          data: {
            courseCount: "",
            id: '',
            intro: "",
            name: ''
          },
          endTm: "",
        }
        infoDocIquery(parameter).then(res => {
          res.data.records.forEach(e=> {
            e.id = e.id +''
          })
          this.flfgList = res.data.records
        }).catch(err => {

        })
      },
      //获取绑定法律法规
      handleChange(value) {
        this.$emit('update:flfgValueList',value)
      },
//          新增
      createData() {
        this.loading = true
        let docs=[];
        this.flfgValueList.forEach(item => docs.push({
          id:item
        }));
        const parameter = {
          address: this.mdl.formData.address,
          certNo: this.mdl.formData.certNo,
          companyName: this.mdl.formData.companyName,
          companyType: 1,
          createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
          dealTime: this.mdl.formData.dealTime,
          del: 0,
          id: '',
          personName: this.mdl.formData.personName,
          pulishNo: this.mdl.formData.pulishNo,
          pulishTime: this.mdl.formData.pulishTime,
          infoDocIList: docs,
//          docName: "法律法规1"
          integral: this.mdl.formData.integral,
          period:  this.mdl.formData.period,
        }
        companyInfoBaseinsert(parameter).then(res => {
          this.loading = false
          if(res.code === 200) {
            this.upShow(1,"添加数据")
            this.mdl.visible = false
            this.$emit('handleSearch')
          } else {
            this.upShow(2,res.msg)
          }
        }).catch(err => {
          this.loading = false
          this.upShow(2)
        })
      },
//      编辑
      updateData() {
        this.loading = true
        let docs=[];
        this.flfgValueList.forEach(item => docs.push({
          id:item
        }));
        const parameter = {
          address: this.mdl.formData.address,
          certNo: this.mdl.formData.certNo,
          companyName: this.mdl.formData.companyName,
          companyType: 1,
          createTime: this.mdl.formData.createTime,
          dealTime: this.mdl.formData.dealTime,
          del: 0,
          id: this.mdl.formData.id,
          personName: this.mdl.formData.personName,
          pulishNo: this.mdl.formData.pulishNo,
          pulishTime: this.mdl.formData.pulishTime,
          infoDocIList: docs
        }
        companyInfoBaseup(parameter).then(res => {
          this.loading = false
          if(res.code === 200) {
            this.upShow(1,"编辑成功")
            this.mdl.visible = false
            this.$emit('handleSearch')
          } else {
            this.upShow(2,res.msg)
          }
        }).catch(err => {
          this.loading = false
          this.upShow(2)
        })
      },
//      处罚日期，处理期限
      onChangepulishTime(data,dateString) {
        this.mdl.formData.pulishTime = dateString
      },
      onChangedealTime(data,dateString) {
        this.mdl.formData.dealTime = dateString
      },
    }
  }
</script>